﻿using System;

namespace NLite.Log
{
    /// <summary>
    /// 日志工厂类
    /// </summary>
    public class LogManager
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public virtual ILog CreateLogger(Type type)
        {
            return new DebugLogger { Name = type.Name };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual ILog CreateLogger(string name)
        {
            return new DebugLogger { Name = name };
        }
        /// <summary>
        /// 
        /// </summary>
        protected LogManager() { }

        private static LogManager instance = null;
        /// <summary>
        /// 
        /// </summary>
        public static LogManager Instance
        {
            get
            {
                if (instance == null)
                {
                    if (Log4NetLogger.LogManagerType == null)
                        instance = new LogManager();
                    else
                        instance = new Log4nLogManager();
                }
                return instance;
            }
            set
            {
                instance = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ILog GetLogger(Type type)
        {
            return Instance.CreateLogger(type);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ILog GetLogger(string name)
        {
            return Instance.CreateLogger(name);
        }

        class Log4nLogManager : LogManager
        {
            public override ILog CreateLogger(string name)
            {
                return new Log4NetLogger(name);
            }

            public override ILog CreateLogger(Type type)
            {
                return new Log4NetLogger(type);
            }


        }
    }

   
}
